package com.sctu.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.sctu.EMSApp.MyTravelNoteActivity;
import com.sctu.EMSApp.R;
import com.sctu.EMSApp.TravelNotesListActivity;
import com.sctu.bean.MyinfoManageNotes;

import java.util.List;

/**
 * Created by zhengsenwen on 2015/12/27.
 */
public class MyinfoMangeNotesAdapter extends BaseAdapter {

    private Activity context;
    private List<MyinfoManageNotes.Results> list;

    public MyinfoMangeNotesAdapter(Activity context, List<MyinfoManageNotes.Results> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        if (list != null && list.size() > 0) {
            return list.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_myinfo_manage_list, null);

        TextView title = (TextView) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_title_txt);
        title.setText(list.get(position).getTitle());

        //编辑和删除
        RelativeLayout edit = (RelativeLayout) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_edit);
        edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "两次输入的密码不对", Toast.LENGTH_LONG).show();
            }
        });

        RelativeLayout delete = (RelativeLayout) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context, "删除", Toast.LENGTH_LONG).show();
            }
        });

        //游记内容  跳转到游记详情页面
        TextView content = (TextView) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_content_txt);
        content.setText(list.get(position).getContent());
        content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyTravelNoteActivity.actionStart(Integer.toString(list.get(position).getId()),context);
            }
        });

        //日期
        TextView pubdate = (TextView) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_date_txt);
        pubdate.setText(list.get(position).getPubdate());


        //阅读数量  赞数  评论数
        TextView commentnumber = (TextView) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_comment_number);
        commentnumber.setText(Integer.toString(list.get(position).getCommentJsonList().size()));

//        TextView praisnuumber = (TextView) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_praise_number);
//        commentnumber.setText(Integer.toString(list.get(position).getCommentJsonList().size()));
//
//        TextView readnumber = (TextView) view.findViewById(R.id.item_activity_myinfo_manage_travel_notes_read_number);
//        commentnumber.setText(Integer.toString(list.get(position).getCommentJsonList().size()));

        return view;
    }
}


            //base64ToBitmap
//    public static Bitmap base64ToBitmap(String base64Data) {
//        byte[] bytes = Base64.decode(base64Data, Base64.DEFAULT);
//        return BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
//    }